﻿namespace class_14_1_方法的参数类型
{
    internal class Program
    {
        static void Main(string[] args)
        {
            int[] b = { 3, 9, 4, 7, 11, 2, 0, 8 };
            int n = 6;
            int q,c;
            Params1(3,5,9,2,4,6,8);


            Ref1(ref n);
            Console.WriteLine(n);
            Ref2(ref b );
            foreach(int g in b)
                Console.Write(g+" ");
            Console.WriteLine();


            Out1(out q, out c);
            Console.WriteLine(q+" "+c);


         
        }
        //params参数
        //patama参数会将输入的实参集体封装为一维数组
        public static void Params1(params  int[] list)
        {
            int min;
            for (int i = 0; i < list.Length - 1; i++)
            {
                int j;
                min = i;
                for (j = i + 1; j < list.Length; j++)
                {
                    if (list[j] < list[min])
                    {
                        min = j;
                    }                   
                }
                int p = list[i];
                list[i] = list[min];
                list[min] = p;
            }
            foreach (int n in list) 
            {
                Console.Write(n+" ");
            }

            Console.WriteLine();
        }

        //ref参数
        //ref参数可以修改传入的实参，并影响main中的变量数值
        //实参必须初始化
        public static void Ref1(ref int mn)
        {
            mn = 7;//会直接改变main中变量n的值
        }
        //ref修改数组test
        public static void Ref2(ref int[] jk)
        {
            int w, k;
            for (int y=0;y<jk.Length-1; y++)
            {
                k = y + 1;
            id:
                if (jk[y] > jk[k])
                {
                    w = jk[y];
                    jk[y] = jk[k];
                    jk[k] = w;
                    goto id;
                }
                else
                {
                    if (k < jk.Length - 1)
                    {
                        k++;
                        goto id;
                    }
                }
            }

        }

        //out参数
        //实参不必初始化
        //可以返回多个值
        public static void Out1(out int y,out int t)
        {
            y = 34;
            t = 99;
        }
    }
}
